package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kaili.basic.mapper.PushMapper;
import com.kaili.basic.pojo.dto.MdmPushPageListDto;
import com.kaili.basic.pojo.entity.MdmPushEntity;
import com.kaili.basic.pojo.vo.MdmPushPageListVo;
import com.kaili.basic.pojo.vo.MdmPushVo;
import com.kaili.basic.service.IMdmPushPushgroupSerivce;
import com.kaili.basic.service.IMdmPushSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Desc: 推送管理ServiceImpl
 * @author: jianfeng
 * @Time: 2019/7/31 10:34
 * @Copyright: © 2018 杭州凯立通信有限公司 版权所有
 * @Warning: 本内容仅限于公司内部传阅, 禁止外泄或用于其它商业目的
 */
@Service
public class PushSerivceImpl extends ServiceImpl<PushMapper, MdmPushEntity> implements IMdmPushSerivce {

     @Autowired
     private IMdmPushPushgroupSerivce mdmPushStategyPushgroupSerivce;


     /**
     * @Desc:  新增推送
     * @author: jianfeng
     * @Time: 2019/7/31 16:55
     * @param entity
     * @return java.lang.Integer
     */
    @Override
    public Integer add(MdmPushEntity entity) {
        // 1.插入主表
        baseMapper.insert(entity);
        // 2.插入从表
        mdmPushStategyPushgroupSerivce.add(entity);

        return 1;
    }

    /**
     * @Desc:  分页展示推送管理
     * @author: jianfeng
     * @Time: 2019/7/31 10:35
     * @param page
     * @param pushPageListDto
     * @return com.baomidou.mybatisplus.plugins.Page<com.kaili.basic.pojo.vo.MdmPushPageListVo>
     */
    @Override
    public Page<MdmPushPageListVo> queryPageList(Page<MdmPushPageListVo> page, MdmPushPageListDto pushPageListDto) {
        return page.setRecords(baseMapper.queryPageList(page,pushPageListDto));
    }

    /**
    * @Desc:  推送管理导出
    * @author: jianfeng
    * @Time: 2019/7/31 11:20
    * @param pushPageListDto
    * @return java.util.List<com.kaili.basic.pojo.vo.MdmPushPageListVo>
    */
    @Override
    public List<MdmPushPageListVo> export(MdmPushPageListDto pushPageListDto) {
        return baseMapper.queryPageList(pushPageListDto);
    }

    /**
    * @Desc:  修改推送
    * @author: jianfeng
    * @Time: 2019/8/1 10:24
    * @param entity
    * @return java.lang.Integer
    */
    @Override
    public Integer modify(MdmPushEntity entity) {
        //1、修改主表信息
        baseMapper.updateById(entity);
        //2、修改关联表信息
        mdmPushStategyPushgroupSerivce.modify(entity);

        return 1;
    }

    /**
    * @Desc:  根据id查询信息
    * @author: jianfeng
    * @Time: 2019/8/1 13:50
    * @param id
    * @return com.kaili.basic.pojo.vo.MdmPushPageListVo
    */
    @Override
    public MdmPushVo queryById(Integer id) {
        List<MdmPushVo> list=baseMapper.queryById(new HashMap<String,Object>(2){{
            put("id",id);
        }});
        if (list!=null&&list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
